﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;
using System.Net.Sockets;

namespace Jp.NicoVideo.Live.Api
{
    class Broadcast
    {
        /// <summary>
        /// 運営者コメントを送信する。
        /// </summary>
        /// <param name="comment">送信する運営者コメント。</param>
        /// <param name="liveId">生放送ID。</param>
        public static void SendComment(string comment, string liveId)
        {
            string url = String.Format("http://watch.live.nicovideo.jp/api/broadcast/{0}", liveId);
            byte[] content = Encoding.ASCII.GetBytes(String.Format("body={0}&mail=", comment));
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.CookieContainer = CookieMonster.Vomit();
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = content.Length;

            Stream stream = request.GetRequestStream();
            {
                stream.Write(content, 0, content.Length);
                stream.Close();
            }

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                string s = reader.ReadToEnd();
                //Console.WriteLine(dataSet.stream.Count);

                //if (dataSet.getplayerstatus.Count != 0 &&
                //    dataSet.getplayerstatus[0].status == "ok")
                //{
                //    return true;
                //}
            }
        }
    }
}
